﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace EEDS.Core
{
    public abstract class PaletteConverter
    {
        public Emblem ConvertToPalette(Emblem emblem, Palette newPalette)
        {
            Emblem newEmblem;
            newEmblem = new Emblem(new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format4bppIndexed), newPalette);

            ConvertToPalette(emblem.Image, newEmblem.Image, newPalette);

            return newEmblem;
        }

        public Bitmap ConvertToPalette(Bitmap emblem, Palette newPalette)
        {
            Bitmap newEmblem;
            newEmblem = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format4bppIndexed);

            ConvertToPalette(emblem, newEmblem, newPalette);

            return newEmblem;
        }

        public void ConvertToPalette(Bitmap inEmblem, Bitmap outEmblem, Palette newPalette)
        {
            for (int x = 0; x < inEmblem.Width; x++)
            {
                for (int y = 0; y < inEmblem.Height; y++)
                {
                    outEmblem.SetPixel(x, y, this.ClosestColour(inEmblem, new Point(x, y), newPalette));
                }
            }
        }
        
        public abstract Color ClosestColour(Bitmap emblem, Point pixel, Palette palette);
        public abstract Palette[] ClosestPalettes(Bitmap emblem, Palette[] palettes);
    }
}
